package com.travelsky.app.action.login;
import java.util.Map;

import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.InterceptorRefs;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.travelsky.app.frame.FrameConst;
import com.travelsky.app.persistence.User;
import com.travelsky.app.security.support.SecurityUserHolder;
@Results( { 
    @Result(name = "authFail", type = "dispatcher", location = "/jsp/public/login.jsp", params = {}),
    @Result(name = "success", type = "dispatcher", location = "/jsp/public/index.jsp", params = {}),
})
public class LoginAction extends ActionSupport {
    /**
     * @Fields serialVersionUID : TODO
     */
   	
    private static final long serialVersionUID = 8508052218594303285L;

	public String execute() throws Exception {
	   User currentUser  = SecurityUserHolder.getCurrentUser();
	   if(currentUser == null){
           return "authFail";
       }
	   Map session = ActionContext.getContext().getSession();
       User sysUserVO=(User) session.get(FrameConst.USER_INFO_BACK);
	   if(sysUserVO != null){
           session.remove(FrameConst.USER_INFO_BACK);
       }
       else{
           session.put(FrameConst.USER_INFO_BACK, sysUserVO);
       }
       return "success";
	}
	
}
